home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-02-07 | 9.8 KB | 229 lines | [TEXT/MPS ] |
- UNIT UDialogUtils;
-
- {-------------------------------------------------------------------------------
- #
- # Apple Macintosh Developer Technical Support
- #
- # Interfaces for the dialog utilities
- #
- # Program: ProcDoggie
- # File: UDialogUtils.p - Pascal Implementation
- #
- # by: Forrest Tanaka
- #
- # Copyright © 1988-1991 Apple Computer, Inc.
- # All rights reserved.
- #
- --------------------------------------------------------------------------------
- #
- # This unit is an embryonic version of an alternative to the Dialog Manager.
- # Why replace the Dialog Manager? For dialogs with just a few basic items like
- # some static text and some buttons, the Dialog Manager isn’t too bad. It still
- # doesn’t handle low-memory situations at all well nor does it handle cases in
- # which some resources are missing with much grace, but a small dialog shouldn’t
- # have too many problems with low-memory situations and clever memory
- # management can avoid all problems, and missing resources is an anomalous
- # situation. The Dialog Manager exposes its problems once a dialog starts to
- # get a bit complicated. User items and controls become difficult to manage,
- # and even something as simple as a static text item that’s in a different size
- # or style becomes a major hassle to implement. The ictb mechanism introduced
- # on Color QuickDraw machines was supposed to make it easier to specify static
- # and edit text styles, but this mechanism is so buggy that it’s useless in my
- # opinion. Another problem with the Dialog Manager is its slow performance when
- # drawing items. Technical Note #203 “Don’t Abuse the Managers” has many words
- # of wisdom when it comes to the Dialog Manager, like don’t use it.
- #
- # Of course, the usual reply we get to this is, “But ResEdit’s DITL editor makes
- # arranging dialogs so easy!” This is true, and I think it’s a compelling
- # argument. This also makes localization very easy, which isn’t a trivial
- # concern. But who said that only the Dialog Manager can read DITLs? The
- # structure of a DITL is very well-defined, and couldn’t possibly change without
- # breaking every program that put up an alert box. DITL resources aren’t that
- # complicated, and your own program can read them as well as the Dialog
- # Manager——better probably.
- #
- # That’s what this unit does. It reads in a DITL, creates an internal item list
- # based on what it found in the DITL, then attaches this item list to the
- # "items" field of a DialogRecord. This unit also contains routines to draw the
- # items and routines to set static text items. And it does this while checking
- # for errors; what a concept!
- #
- # But, as I said, this unit is very embryonic. The first time I tried this, I
- # made it very complete, but I also made it much, much harder to use than the
- # Dialog Manager. So, I almost completely stripped it for the purposes of this
- # sample application. Now, it only handles static text items and buttons, and
- # it no longer handles modal dialogs. Eventually, I want to give this the full
- # functionality of the real Dialog Manager.
- #
- # One capability this unit has that the Dialog Manager doesn’t implement is
- # style information for static text items. I don’t mean one static text item
- # with multiple text styles. I mean different items can have different text
- # styles. Doing this through the Dialog Manager involves much more work than
- # it should. The way I do this while keeping the DITL structure is to use the
- # four bytes used for a placeholder for handle or procedure pointer in Inside
- # Macintosh I page 427. If you want static text items displayed in the standard
- # font, style, and justification, then just leave these four bytes set to 0. If
- # you want to specify the type face, style, size, and line justification, then
- # each of these four bytes can hold each of these pieces of information.
- #
- # The first byte holds a font index. This isn’t a font number because, as
- # Technical Note #191 “Font Names” says, it isn’t nice to save font numbers.
- # This font index is an index into a STR# resource which contains the names of
- # whatever fonts you want to use in this dialog. For example, if the second
- # string in the STR# resource is "Monaco", then a 2 placed into the font index
- # field will cause the DrawDialogItems routine defined in this unit to display
- # that static text item in Monaco. The STR# resource should have a resource ID
- # of 0. This lets all dialog boxes use the same font list. You can override
- # this font list by specifying a STR# resource with an ID equal to the resource
- # ID of the DITL being read. In this way, you can provide a STR# resource ID 0
- # that contains the default font list, and then provide special font lists for
- # for specific DITLs.
- #
- # The second byte holds the style (“face” according to QuickDraw) of the static
- # text item. This holds the same value as the Style type. The third byte
- # contains the point size of the static text. The point size is limited to 255,
- # which shouldn’t be a problem. The last byte contains the justification of the
- # static text. -2 means left justification, -1 means right justification, 0
- # means default justification, and 1 means center justification.
- #
- -------------------------------------------------------------------------------}
- {[j=20/57/1$] Pasmat Options}
-
-
- INTERFACE
-
-
- (*******************************************************************************
- * Used Units
- *******************************************************************************)
-
- USES
- (* Group 1 *)
- Types
- ,QuickDraw
-
- (* Group 2 *)
- ,Controls
- ,Errors
- ,Events
- ,Fonts
- ,Memory
- ,Resources
- ,TextEdit
- ,ToolUtils
-
- (* Group 3 *)
- ,Windows
-
- (* Group 4 *)
- ,Dialogs
-
- (* Application *)
- ,UEmergMem
- ;
-
-
- (*******************************************************************************
- * Constants
- *******************************************************************************)
-
- CONST
- kNoItem = -1; {No dialog item is applicable or end of dialog item list}
-
-
- (*******************************************************************************
- * Types
- *******************************************************************************)
-
- TYPE
- (* Type information for static text items *)
- TypeInfoRec = RECORD
- typeFace: Integer; {Font number of text}
- typeSize: Integer; {Font size of text}
- textJust: Integer; {Justification of text}
- typeStyle: Style; {Font style of text}
- END;
-
-
- (*******************************************************************************
- * InstallDialogItems - Install a DITL into a dialog window
- *
- * This routine is called to install a DITL into the dialog window specified by
- * "aDialog". The resource ID of the desired DITL is specified by "itemListNum".
- * InstallDialogItems returns noErr if the item list was successfully created and
- * attached to aDialog, otherwise, an operating system error code is returned.
- *******************************************************************************)
-
- FUNCTION InstallDialogItems (aDialog: DialogPtr;
- itemListNum: Integer): OSErr;
-
-
- (*******************************************************************************
- * SetStatTextItem - Set a static text dialog item to the specified text
- *
- * This routine sets the text of a static text item to the text pointed to by
- * "textPtr" and having the length "textLength". "aDialog" is a pointer to the
- * dialog box that this is being done in, and "itemNum" is the item number of the
- * static text item to set. If that item isn’t actually a static text item, then
- * nothing is done. If there isn’t enough memory to put the text into the static
- * text item, then nothing is done.
- *******************************************************************************)
-
- PROCEDURE SetStatTextItem (aDialog: DialogPtr;
- itemNum: Integer;
- textPtr: Ptr;
- textLength: Integer);
-
-
- (*******************************************************************************
- * GetStatTextFontInfo - Get font information for a static text item
- *
- * This routine gets the font information for the static text item with an item
- * number of "itemNum" in the dialog specified by "aDialog". This font
- * information is returned in "typeInfo". The the specified item isn’t a static
- * text item, then nothing is done.
- *******************************************************************************)
-
- PROCEDURE GetStatTextFontInfo (aDialog: DialogPtr;
- itemNum: Integer;
- VAR typeInfo: TypeInfoRec);
-
-
- (*******************************************************************************
- * DrawDialogItems - Draw all standard dialog items
- *
- * All standard dialog items in the dialog box pointed to by "aDialog" are drawn.
- *******************************************************************************)
-
- PROCEDURE DrawDialogItems (aDialog: DialogPtr);
-
-
- (*******************************************************************************
- * GetDialogItemRect - Get the item rectangle of a specified dialog item
- *
- * This routine gets the item rectangle of the dialog item in the dialog box
- * specified by "aDialog" and having an item number of "itemNum". This rectangle
- * is returned in "itemRect".
- *******************************************************************************)
-
- PROCEDURE GetDialogItemRect (aDialog: DialogPtr;
- itemNum: Integer;
- VAR itemRect: Rect);
-
-
- (*******************************************************************************
- * DisposeDialogItems - Dispose of all dialog items in the specified dialog box
- *
- * This routine disposes of the memory used by all the dialog items in the dialog
- * box specified by "aDialog". The item list itself is also deallocated.
- *******************************************************************************)
-
- PROCEDURE DisposeDialogItems (aDialog: DialogPtr);
-
-
- IMPLEMENTATION
-
- {$I UDialogUtils.inc1.p}
-
- END.
-